package com.amiu.shiro.db.role;

import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Select;


public interface RoleDao {
	public Role createRole(Role role);

	@Delete("DELETE from role where id=#{id}")
	public void deleteRole(Long id);

	public void updateRole(Long id);
	
	@Select("SELECT id,name,sort,description FROM role WHERE id=#{id}")
	public Role findById(Long id);
	
	@Select("SELECT id,name,sort,description FROM role WHERE name=#{name}")
	public Role findByName(String name);
	
	@MapKey("id")
	@Select("SELECT id,name,sort,description FROM role")
	public Map<Long, Role> findAll();
	
	@Select("select * from role where id in (select `role_id` from user_roles where user_id = #{userId})")
	public Map<Long, Role> findRoleByUserId(Long userId);
	
	// 添加角色-权限之间关系
	public void correlationPermissions(Long roleId, Long... permissionIds);

	// 移除角色-权限之间关系
	public void uncorrelationPermissions(Long roleId, Long... permissionIds);//
}
